package com.pzhuweb.sgblog.controller;

import com.pzhuweb.sgblog.service.ArticleService;

import com.pzhuweb.sgblog.domain.utils.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * @author 鄧浩奇
 * @classname ArticleController
 * @description
 * @since 2023/6/10 16:49
 **/

@RestController // 响应的东西在响应体中，不能用于跳转页面
@RequestMapping("/article")
@Api(description = "文章列表接口")
public class ArticleController {

    @Resource
    private ArticleService articleService;

    @GetMapping("/hotArticleList")
    @ApiOperation(value = "获取热门文章")
    public ResponseResult<?> hotArticle() {
         return articleService.hotArticle();
    }

    @GetMapping("/articleList")
    @ApiOperation(value = "获取所有文章列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页号"),
            @ApiImplicitParam(name = "pageSize", value = "一页里面的评论数目"),
            @ApiImplicitParam(name = "categoryId",value = "文章所属分类标签的id")
    })
    public ResponseResult<?> articleList(Integer pageNum,Integer pageSize,Long categoryId) {
        return articleService.articleList(pageNum,pageSize,categoryId);
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "获取文章详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "文章id"),
    })
    public ResponseResult<?> getArticlesDetail(@PathVariable("id") Long id) {
        return articleService.getArticlesDetail(id);
    }


    @PutMapping("updateViewCount/{id}")
    @ApiOperation(value = "获取文章浏览量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "文章id",example = "1"),
    })
    public ResponseResult<?> updateViewCount(@PathVariable("id") Long id) {
        return articleService.updateViewCount(id);
    }

}
